namespace devtm.Aop.Emit
{
    using System;
    
    using System.Runtime.Serialization;
    using Mono.Cecil;
    using Mono.Cecil.Cil;

    [Serializable]
    public class EmitMethodReferenceExpression : EmitExpression
    {

        private EmitExpression targetObject;

        private EmitTypeReferenceCollection typeArguments;

        public EmitMethodReferenceExpression()
        {
        }

        public EmitMethodReferenceExpression(EmitExpression targetObject, MethodReference method)
        {
            this.TargetObject = targetObject;
            this.Method = method;
        }

        public EmitMethodReferenceExpression(MethodReference method)
        {
            this.Method = method;
        }



        public MethodReference Method { get; set; }

        public EmitExpression TargetObject { get; set; }

        private EmitMethodInvokeExpression _invoke;
        public EmitMethodInvokeExpression Invoke(params EmitExpression[] args)
        {
            _invoke = new EmitMethodInvokeExpression(this, args);

            return _invoke;
        }


        public override void Compile(CilWorker gen)
        {

            foreach (EmitExpression item in _invoke.args)
            {
                item.UserData.Add("way", "get");
                item.Compile(gen);
                item.UserData.Clear();
            }
            

            _invoke.Compile(gen);

        }

     
    }
}
